<%@page import="lib_model.Factories.Stocks_factory"%>
<%@page import="lib_model.Product.Products"%>
<%@page import="lib_model.Account.Account"%>
<%@page import="lib_model.Factories.Factory"%>
<%@page import="lib_model.Orther.ReturnObj"%>
<%@page import="java.util.ArrayList"%>
<%@page import="lib_model.Account.Account_factory"%>
<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
<jsp:include page="../templates/Factories.jsp"></jsp:include>
Manager Stock Factory
<jsp:include page="../templates/Title.jsp"></jsp:include>
<link rel="stylesheet"
	href="http://dev.jquery.com/view/trunk/plugins/autocomplete/jquery.autocomplete.css"
	type="text/css" />
<script type="text/javascript"
	src="http://dev.jquery.com/view/trunk/plugins/autocomplete/lib/jquery.bgiframe.min.js"></script>
<script type="text/javascript"
	src="http://dev.jquery.com/view/trunk/plugins/autocomplete/lib/jquery.dimensions.js"></script>
<script type="text/javascript"
	src="http://dev.jquery.com/view/trunk/plugins/autocomplete/jquery.autocomplete.js"></script>
<script type="text/javascript">
	$(document).ready(function() {
		$("#createfac").hide();
		$("#btcreate").click(function() {
			$("#createfac").fadeIn();
		});
	});
</script>
<%
	Products ac = new Products();
	ArrayList<Products> lac = (ArrayList<Products>) ac.Select().ObjResult;
	String a = "";
	for (Products acs : lac) {
		a += acs.name + "@";
	}
%>
<script>
	$(document).ready(function() {
		var data = "<%=a%>".split("@");
		$("#example").autocomplete(data);
		$(".historyc").click(function(){
			window.location = "../factories/stock-history.jsp?idproduct="+ $(this).attr("proid")+ "&idfactory="+ $(this).attr("proidfac");
		});
	});
</script>
<jsp:include page="../templates/StyleFac.jsp"></jsp:include>
<div class="body-center w960">
<h2 class="title-show">Manager Account Factories</h2>
<table class="tb">
	<thead>
		<tr>
			<th align="left" width="20%">Factory</th>
			<th align="left" width="20%">Product</th>
			<th align="left" width="20%">Quantity</th>
			<th align="left" width="20%">Date Create</th>
		</tr>
	</thead>
	<tbody>
		<%
			Account acc = (Account) request.getSession().getAttribute("User");
			String usn = acc.username;
			int fac_id = 0;
			fac_id = ((Account_factory) (new Account_factory(usn)
					.GetInformation().ObjResult)).factory_id_ref;
			if (fac_id == 0) {
				request.getSession().removeAttribute("User");
				response.sendRedirect("../pages/home.jsp");
			} else {
				Stocks_factory fast = new Stocks_factory();
				ArrayList<Stocks_factory> arr = (ArrayList<Stocks_factory>) fast
						.SelectByIDfactory(fac_id).ObjResult;
				for (Stocks_factory fac : arr) {
		%>
		<tr>
			<td><b><%=((Factory) ((new Factory(fac_id))
							.GetInformation().ObjResult)).name%></b></td>
			<td><%=((Products) ((new Products(fac.products_id_ref))
							.GetInformation().ObjResult)).name%> <a target="_black"
				href="../pages/product-detail.jsp?id=<%=fac.products_id_ref%>">View</a></td>
			<td><%=fac.quantity%></td>
			<td><%=fac.date_create%></td>
			<td><input type="button" value="History" class="historyc"
				proidfac="<%=fac.factory_id_ref%>"
				proid="<%=fac.products_id_ref%>" /></td>
		</tr>
		<%
			}
			}
		%>
	</tbody>
</table>
<br>
<br>
<input type="button" id="btcreate" value="Add Stock to Factories" /> <%
 	if (request.getAttribute("Mes") != null) {
 %>
<h2><%=request.getAttribute("Mes")%></h2>
<%
	}
%>
<form action="../factories/AddStock" method="post">
<table class="tb" style="width: 300px;" id="createfac">
	<thead>
		<tr>
			<th align="left" width="20%"></th>
			<th align="left" width="20%"></th>
		</tr>
		<tr>
			<td>Product</td>
			<td><input id="example" type="text" name="txtName" /></td>
		</tr>
		<tr>
			<td>Quantity</td>
			<td><input type="text" name="txtQuan" /></td>
		</tr>
		<tr align="center">
			<td colspan="2"><input type="submit" value="Add"></td>
		</tr>
	</thead>
</table>
</form>
</div>
<jsp:include page="../templates/Footer.jsp"></jsp:include>